//
//  DLBaseSearchVC.m
//  DontRem
//
//  Created by apple on 2021/1/15.
//

#import "DLBaseSearchVC.h"
#define margin 5
#define navH kTopHeight + kNavBarHeight+margin
@interface DLBaseSearchVC ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)UIView * bgView;
@property(nonatomic,retain)UIButton * cancelBtn , * navRightBtn, * navLeftBtn;
@end

@implementation DLBaseSearchVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
}
- (void)textFieldDidChangeValue:(UITextField*)textField{
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [self beginInput];
    self.navRightBtn.hidden = self.navLeftBtn.hidden = YES;
    self.cancelBtn.hidden = NO;
    [UIView animateWithDuration:0.35 animations:^{
        self.baseNavView.height = kTopHeight+margin;
        self.bgView.y = kStatusBarHeight;
        self.inputTF.sd_resetLayout.spaceToSuperView(UIEdgeInsetsMake(5, 26, 5, 95));
        self.myTab.frame = Frame(0, kTopHeight + margin, SCREEN_WIDTH, SCREEN_HEIGHT - kTopHeight - margin - kTopHeight);
    }];
    return YES;
}
-(void)cancelBtnClick{
    [self.view endEditing:YES];
    [self cancelInput];
    self.cancelBtn.hidden = YES;
    self.navRightBtn.hidden = self.navLeftBtn.hidden = NO;
    [UIView animateWithDuration:0.35 animations:^{
        self.bgView.y = kTopHeight;
        self.inputTF.sd_resetLayout.spaceToSuperView(UIEdgeInsetsMake(5, 26, 5, 10));
        self.baseNavView.height = navH;
        self.myTab.frame = Frame(0, navH, SCREEN_WIDTH, SCREEN_HEIGHT - navH - KTabbarSafeBottomMargin);
    }completion:^(BOOL finished) {
        [self cancelInputAniEnd];
    }];
}
-(void)textFieldInputChange:(NSString * )text{
    
}
-(void)beginInput{
    
}
-(void)cancelInput{
    
}
-(void)cancelInputAniEnd{
    
}
-(void)navRightBtnClick{
}
-(void)navLeftBtnClick{
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    return YES;
}
-(void)createUI{
    [self.view addSubview:self.myTab];
}
- (void)createNavBar{
    self.baseNavView = [[UIView alloc]initWithFrame:Frame(0, 0, SCREEN_WIDTH, navH)];
    self.baseNavView.backgroundColor = UIColorWhite;
    [self.view addSubview:self.baseNavView];
    
    self.navRightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.navRightBtn setImage:Image(@"加号") forState:UIControlStateNormal];
    [self.navRightBtn addTarget:self action:@selector(navRightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.baseNavView addSubview:self.navRightBtn];
    self.navRightBtn.sd_layout.rightSpaceToView(self.baseNavView, 0).topSpaceToView(self.baseNavView, kStatusBarHeight).widthIs(kNavBarHeight).heightEqualToWidth();
    
    self.navLeftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.navLeftBtn setImage:Image(@"更多") forState:UIControlStateNormal];
    [self.navLeftBtn addTarget:self action:@selector(navLeftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.baseNavView addSubview:self.navLeftBtn];
    self.navLeftBtn.sd_layout.leftSpaceToView(self.baseNavView, 0).topSpaceToView(self.baseNavView, kStatusBarHeight).widthIs(kNavBarHeight).heightEqualToWidth();
    
    UIView * line = [[UIView alloc]initWithFrame:Frame(0, self.baseNavView.mm_h-0.7, SCREEN_WIDTH, 0.7)];
    line.backgroundColor = UnderLineColor;;
    [self.baseNavView addSubview:line];
    
    self.bgView = [[UIView alloc]initWithFrame:Frame(15, kTopHeight, SCREEN_WIDTH-30, kNavBarHeight)];
    self.bgView.backgroundColor = UnderLineColor;
    self.bgView.cornerRadius = 7;
    [self.view addSubview:self.bgView];
    
    UIImageView * fangda = [UIImageView new];
    fangda.image = Image(@"放大镜");
    [self.bgView addSubview:fangda];
    fangda.sd_layout.leftSpaceToView(self.bgView, 5).centerYEqualToView(self.bgView).widthIs(16).heightEqualToWidth();
    
    self.inputTF = [UITextField new];
    self.inputTF.placeholder = @"请输入内容";
    self.inputTF.placeholderColor = UIColorGrayLighten;
    self.inputTF.font = UIFontMake(AUTO(15));
    self.inputTF.textColor = DLDarkGrayBlueColor;
    self.inputTF.delegate = self;
    self.inputTF.returnKeyType = UIReturnKeySearch;
    [self.inputTF addTarget:self action:@selector(textFieldDidChangeValue:)  forControlEvents:UIControlEventEditingChanged];
    [self.bgView addSubview:self.inputTF];
    self.inputTF.sd_layout.leftSpaceToView(fangda, 5).centerYEqualToView(fangda).heightIs(35).rightEqualToView(self.bgView);
    
    self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.cancelBtn setTitleColor:DLDarkGrayBlueColor forState:UIControlStateNormal];
    self.cancelBtn.hidden = YES;
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = UIFontMake(AUTO(14));
    [self.cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.cancelBtn];
    self.cancelBtn.sd_layout.rightSpaceToView(self.bgView, 10).centerYEqualToView(self.bgView);
    [self.cancelBtn setupAutoSizeWithHorizontalPadding:10 buttonHeight:30];
}
#pragma mark 代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
- (UITableView *)myTab{
    if (!_myTab) {
        _myTab = [[UITableView alloc]initWithFrame:Frame(0, self.baseNavView.mm_maxY, SCREEN_WIDTH, SCREEN_HEIGHT - self.baseNavView.mm_maxY - KTabbarSafeBottomMargin) style:UITableViewStyleGrouped];
        _myTab.delegate = self;
        _myTab.dataSource = self;
        _myTab.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTab.backgroundColor = UIColorClear;
    }
    return _myTab;
}
@end
